// 引入unocss.css
import 'virtual:uno.css'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import 'fetm-components/dist/style.css'

import * as elementIcons from '@element-plus/icons-vue'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import { createApp } from 'vue'
;

(async () => {
  const ElementIconsInstaller = {
    install: (app: any) => {
      for (const key in elementIcons) {
        const componentConfig = (elementIcons as Record<string, any>)[key]
        app.component(componentConfig.name, componentConfig)
      }
    },
  }

  const apps = import.meta.glob<any>('./src/*.vue')
  const name = location.pathname.replace(/^\//, '') || 'App'
  const file = apps[`./src/${name}.vue`]
  if (!file) {
    location.pathname = 'App'
    return
  }
  const App = (await file()).default
  const app = createApp(App)
  app
    .use(ElementPlus, {
      locale: zhCn,
      zIndex: 20250605,
      emptyValues: [undefined, null],
    })
    .use(ElementIconsInstaller)
  app.mount('#play')
})()
